<?php
namespace app\index\model;
use think\Model;
class Tap extends Model
{
    public function list()
    {
       return $this->where('is_show' , 1)->select();
    }
    static public function handleSpliceToArr(Array $tap)
    {
        if (isset($tap)) {
            $keys = array_keys($tap);
            $k = '';
            foreach ($keys as $key) {
                if(is_numeric($key))
                {
                    if(!self::findOrEmpty($key)->isEmpty()) 
                    {
                        $k .= $key . ',';
                    }
                }
            }
        } else $k = '';
        return $k;
    }
    // 
    /**
     * @param string $art_id文章ID
     * 返回对应文章的标签       1,2,3得到分别的标签名称
     */
    public function get($articleId){
        $articleTap = Article::where('id' , $articleId)->value('tap_id');
        $tapArr = explode(',',$articleTap);
        $list = [];
        foreach($tapArr as $t => $j){
            $val = $this->where(['id' => $j , 'is_show' => 1])->value('tap');
            if($val != '')
            {
                $list[$t]['id'] = $j;
                $list[$t]['name'] = $val;
            }
        }
        return  $list;
    }
    public static function hasTag($id)
    {
        $res = self::findOrEmpty($id)->isEmpty();
        if($res) return 0;
        return self::find($id)->tap;
    }
}